package com.kelaite.procurement.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kelaite.procurement.entity.TPurchaseOrderExecutionItems;
import com.kelaite.procurement.repository.PurchaseOrderExecutionItemsRepository;
import com.kelaite.procurement.service.PurchaseOrderExecutionItemsService;

@Service
@Transactional
public class PurchaseOrderExecutionItemsServiceImpl implements PurchaseOrderExecutionItemsService{
  
	@Autowired
	private PurchaseOrderExecutionItemsRepository purchaseOrderExecutionItemsRepository; 
	
	@PersistenceContext
	private EntityManager em;
	
	@Override
	public TPurchaseOrderExecutionItems save(TPurchaseOrderExecutionItems persistence) {
		return this.purchaseOrderExecutionItemsRepository.save(persistence);
	}

	@Override
	public TPurchaseOrderExecutionItems getObject(Long id) {
		return this.purchaseOrderExecutionItemsRepository.findOne(id);
	}

	@Override
	public List<TPurchaseOrderExecutionItems> getAll() {
		return this.purchaseOrderExecutionItemsRepository.findAll();
	}

	@Override
	public void deleteByObject(TPurchaseOrderExecutionItems persistence) {
		this.purchaseOrderExecutionItemsRepository.delete(persistence);
	}

	@Override
	public void deleteByPrimaryKey(Long id) {
		this.purchaseOrderExecutionItemsRepository.delete(id);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<TPurchaseOrderExecutionItems> getByProperty(String property, Object value) {
		Session session = (org.hibernate.Session) em.getDelegate();
		Criteria criteria = session.createCriteria(TPurchaseOrderExecutionItems.class).add(Restrictions.eq(property, value));
		return criteria.list();
	}
	
}
